/*
 * Container.cpp
 */
#include "Container.h"

namespace gui
  {
    
    void Container::add(Component& component)
      {
        component.parent(this);
        _content.push_back(&component);
      }

    Component* Container::get(int index)
      {
        return _content.at(index);
      }
        
    int Container::count() const { return _content.size(); }

    void Container::paint(BITMAP* buffer, int x_offset, int y_offset)
      {
        paintChildren(buffer, x_offset, y_offset);
      }

    void Container::paintChildren(BITMAP* buffer, int x_offset, int y_offset)
      {
        int x = this->x() + x_offset;
        int y = this->y() + y_offset;
        std::vector<Component*>::iterator iter;
        for (iter = _content.begin(); iter != _content.end(); iter++)
          {
            (*iter)->paint(buffer, x, y);
          }
      }
    
    void Container::mask(BITMAP* buffer, int x_offset, int y_offset)
      {
        Component::mask(buffer, x_offset, y_offset);
        maskChildren(buffer, x_offset, y_offset);
      }

    void Container::maskChildren(BITMAP* buffer, int x_offset, int y_offset)
      {
        int x = this->x() + x_offset;
        int y = this->y() + y_offset;
        std::vector<Component*>::iterator iter;
        for (iter = _content.begin(); iter != _content.end(); iter++)
          {
            (*iter)->mask(buffer, x, y);
          }
      }
  }

